package cn.qqtheme.framework.picker;

import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.qqtheme.framework.entity.LinkageFirst;
import cn.qqtheme.framework.entity.LinkageSecond;
import cn.qqtheme.framework.entity.LinkageThird;
import cn.qqtheme.framework.util.LogUtils;
import cn.qqtheme.framework.widget.WheelView;
import java.util.ArrayList;
import java.util.List;

/* loaded from: classes.dex */
public class LinkagePicker<Fst extends LinkageFirst<Snd>, Snd extends LinkageSecond<Trd>, Trd> extends WheelPicker {
    protected float firstColumnWeight;
    protected String firstLabel;
    private OnLinkageListener onLinkageListener;
    private OnPickListener onPickListener;
    private OnWheelLinkageListener onWheelLinkageListener;
    private OnWheelListener onWheelListener;
    protected Provider provider;
    protected float secondColumnWeight;
    protected String secondLabel;
    protected int selectedFirstIndex;
    protected Fst selectedFirstItem;
    protected int selectedSecondIndex;
    protected Snd selectedSecondItem;
    protected int selectedThirdIndex;
    protected Trd selectedThirdItem;
    protected float thirdColumnWeight;
    protected String thirdLabel;

    @Deprecated
    /* loaded from: classes.dex */
    public static abstract class OnLinkageListener extends OnStringPickListener {
    }

    /* loaded from: classes.dex */
    public interface OnPickListener<Fst, Snd, Trd> {
        void onPicked(Fst fst, Snd snd, Trd trd);
    }

    /* loaded from: classes.dex */
    public interface OnWheelLinkageListener {
        void onLinkage(int i, int i2, int i3);
    }

    @Deprecated
    /* loaded from: classes.dex */
    public static abstract class OnWheelListener {
        public abstract void onFirstWheeled(int i, String str);

        public abstract void onSecondWheeled(int i, String str);

        public void onThirdWheeled(int i, String str) {
        }
    }

    /* loaded from: classes.dex */
    public interface Provider<Fst extends LinkageFirst<Snd>, Snd extends LinkageSecond<Trd>, Trd> {
        List<Fst> initFirstData();

        boolean isOnlyTwo();

        List<Snd> linkageSecondData(int i);

        List<Trd> linkageThirdData(int i, int i2);
    }

    public LinkagePicker(Activity activity) {
        super(activity);
        this.firstLabel = "";
        this.secondLabel = "";
        this.thirdLabel = "";
        this.selectedFirstIndex = 0;
        this.selectedSecondIndex = 0;
        this.selectedThirdIndex = 0;
        this.firstColumnWeight = 1.0f;
        this.secondColumnWeight = 1.0f;
        this.thirdColumnWeight = 1.0f;
    }

    public LinkagePicker(Activity activity, DataProvider dataProvider) {
        super(activity);
        this.firstLabel = "";
        this.secondLabel = "";
        this.thirdLabel = "";
        this.selectedFirstIndex = 0;
        this.selectedSecondIndex = 0;
        this.selectedThirdIndex = 0;
        this.firstColumnWeight = 1.0f;
        this.secondColumnWeight = 1.0f;
        this.thirdColumnWeight = 1.0f;
        this.provider = dataProvider;
    }

    public LinkagePicker(Activity activity, Provider<Fst, Snd, Trd> provider) {
        super(activity);
        this.firstLabel = "";
        this.secondLabel = "";
        this.thirdLabel = "";
        this.selectedFirstIndex = 0;
        this.selectedSecondIndex = 0;
        this.selectedThirdIndex = 0;
        this.firstColumnWeight = 1.0f;
        this.secondColumnWeight = 1.0f;
        this.thirdColumnWeight = 1.0f;
        this.provider = provider;
    }

    @Deprecated
    public LinkagePicker(Activity activity, List<Fst> list, List<List<Snd>> list2) {
        this(activity, list, list2, null);
    }

    @Deprecated
    public LinkagePicker(Activity activity, List<Fst> list, List<List<Snd>> list2, List<List<List<Trd>>> list3) {
        super(activity);
        this.firstLabel = "";
        this.secondLabel = "";
        this.thirdLabel = "";
        this.selectedFirstIndex = 0;
        this.selectedSecondIndex = 0;
        this.selectedThirdIndex = 0;
        this.firstColumnWeight = 1.0f;
        this.secondColumnWeight = 1.0f;
        this.thirdColumnWeight = 1.0f;
        this.provider = new DefaultDataProvider(list, list2, list3);
    }

    protected void setProvider(DataProvider dataProvider) {
        this.provider = dataProvider;
    }

    protected void setProvider(Provider<Fst, Snd, Trd> provider) {
        this.provider = provider;
    }

    public void setSelectedIndex(int i, int i2) {
        setSelectedIndex(i, i2, 0);
    }

    public void setSelectedIndex(int i, int i2, int i3) {
        this.selectedFirstIndex = i;
        this.selectedSecondIndex = i2;
        this.selectedThirdIndex = i3;
    }

    public void setSelectedItem(Fst fst, Snd snd) {
        setSelectedItem(fst, snd, null);
    }

    /* JADX WARN: Code restructure failed: missing block: B:29:0x00a9, code lost:
        r7.selectedSecondIndex = r3;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void setSelectedItem(Fst r8, Snd r9, Trd r10) {
        /*
            Method dump skipped, instructions count: 327
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: cn.qqtheme.framework.picker.LinkagePicker.setSelectedItem(cn.qqtheme.framework.entity.LinkageFirst, cn.qqtheme.framework.entity.LinkageSecond, java.lang.Object):void");
    }

    public void setLabel(String str, String str2) {
        setLabel(str, str2, "");
    }

    public void setLabel(String str, String str2, String str3) {
        this.firstLabel = str;
        this.secondLabel = str2;
        this.thirdLabel = str3;
    }

    public Fst getSelectedFirstItem() {
        if (this.selectedFirstItem == null) {
            this.selectedFirstItem = this.provider.initFirstData().get(this.selectedFirstIndex);
        }
        return this.selectedFirstItem;
    }

    public Snd getSelectedSecondItem() {
        if (this.selectedSecondItem == null) {
            this.selectedSecondItem = this.provider.linkageSecondData(this.selectedFirstIndex).get(this.selectedSecondIndex);
        }
        return this.selectedSecondItem;
    }

    public Trd getSelectedThirdItem() {
        if (this.selectedThirdItem == null) {
            List<Trd> linkageThirdData = this.provider.linkageThirdData(this.selectedFirstIndex, this.selectedSecondIndex);
            if (linkageThirdData.size() > 0) {
                this.selectedThirdItem = linkageThirdData.get(this.selectedThirdIndex);
            }
        }
        return this.selectedThirdItem;
    }

    public int getSelectedFirstIndex() {
        return this.selectedFirstIndex;
    }

    public int getSelectedSecondIndex() {
        return this.selectedSecondIndex;
    }

    public int getSelectedThirdIndex() {
        return this.selectedThirdIndex;
    }

    public void setColumnWeight(float f, float f2, float f3) {
        this.firstColumnWeight = f;
        this.secondColumnWeight = f2;
        this.thirdColumnWeight = f3;
    }

    public void setColumnWeight(float f, float f2) {
        this.firstColumnWeight = f;
        this.secondColumnWeight = f2;
        this.thirdColumnWeight = 0.0f;
    }

    public void setOnWheelLinkageListener(OnWheelLinkageListener onWheelLinkageListener) {
        this.onWheelLinkageListener = onWheelLinkageListener;
    }

    @Deprecated
    public void setOnWheelListener(OnWheelListener onWheelListener) {
        this.onWheelListener = onWheelListener;
    }

    public void setOnPickListener(OnPickListener<Fst, Snd, Trd> onPickListener) {
        this.onPickListener = onPickListener;
    }

    public void setOnStringPickListener(OnStringPickListener onStringPickListener) {
        this.onPickListener = onStringPickListener;
    }

    @Deprecated
    public void setOnLinkageListener(OnLinkageListener onLinkageListener) {
        this.onLinkageListener = onLinkageListener;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // cn.qqtheme.framework.popup.ConfirmPopup
    public View makeCenterView() {
        if (this.provider == null) {
            throw new IllegalArgumentException("please set data provider before make view");
        }
        LinearLayout linearLayout = new LinearLayout(this.activity);
        linearLayout.setOrientation(0);
        linearLayout.setGravity(17);
        WheelView createWheelView = createWheelView();
        createWheelView.setLayoutParams(new LinearLayout.LayoutParams(0, -2, this.firstColumnWeight));
        linearLayout.addView(createWheelView);
        if (!TextUtils.isEmpty(this.firstLabel)) {
            TextView createLabelView = createLabelView();
            createLabelView.setText(this.firstLabel);
            linearLayout.addView(createLabelView);
        }
        final WheelView createWheelView2 = createWheelView();
        createWheelView2.setLayoutParams(new LinearLayout.LayoutParams(0, -2, this.secondColumnWeight));
        linearLayout.addView(createWheelView2);
        if (!TextUtils.isEmpty(this.secondLabel)) {
            TextView createLabelView2 = createLabelView();
            createLabelView2.setText(this.secondLabel);
            linearLayout.addView(createLabelView2);
        }
        final WheelView createWheelView3 = createWheelView();
        if (!this.provider.isOnlyTwo()) {
            createWheelView3.setLayoutParams(new LinearLayout.LayoutParams(0, -2, this.thirdColumnWeight));
            linearLayout.addView(createWheelView3);
            if (!TextUtils.isEmpty(this.thirdLabel)) {
                TextView createLabelView3 = createLabelView();
                createLabelView3.setText(this.thirdLabel);
                linearLayout.addView(createLabelView3);
            }
        }
        createWheelView.setItems((List<?>) this.provider.initFirstData(), this.selectedFirstIndex);
        createWheelView.setOnItemSelectListener(new WheelView.OnItemSelectListener() { // from class: cn.qqtheme.framework.picker.LinkagePicker.1
            @Override // cn.qqtheme.framework.widget.WheelView.OnItemSelectListener
            public void onSelected(int i) {
                LinkagePicker linkagePicker = LinkagePicker.this;
                linkagePicker.selectedFirstItem = linkagePicker.provider.initFirstData().get(i);
                LinkagePicker.this.selectedFirstIndex = i;
                LogUtils.verbose(this, "change second data after first wheeled");
                LinkagePicker linkagePicker2 = LinkagePicker.this;
                linkagePicker2.selectedSecondIndex = 0;
                linkagePicker2.selectedThirdIndex = 0;
                List<?> linkageSecondData = linkagePicker2.provider.linkageSecondData(LinkagePicker.this.selectedFirstIndex);
                LinkagePicker linkagePicker3 = LinkagePicker.this;
                linkagePicker3.selectedSecondItem = linkageSecondData.get(linkagePicker3.selectedSecondIndex);
                createWheelView2.setItems(linkageSecondData, LinkagePicker.this.selectedSecondIndex);
                if (!LinkagePicker.this.provider.isOnlyTwo()) {
                    List<?> linkageThirdData = LinkagePicker.this.provider.linkageThirdData(LinkagePicker.this.selectedFirstIndex, LinkagePicker.this.selectedSecondIndex);
                    LinkagePicker linkagePicker4 = LinkagePicker.this;
                    linkagePicker4.selectedThirdItem = linkageThirdData.get(linkagePicker4.selectedThirdIndex);
                    createWheelView3.setItems(linkageThirdData, LinkagePicker.this.selectedThirdIndex);
                }
                if (LinkagePicker.this.onWheelLinkageListener != null) {
                    LinkagePicker.this.onWheelLinkageListener.onLinkage(LinkagePicker.this.selectedFirstIndex, 0, 0);
                }
                if (LinkagePicker.this.onWheelListener != null) {
                    LinkagePicker.this.onWheelListener.onFirstWheeled(LinkagePicker.this.selectedFirstIndex, LinkagePicker.this.selectedFirstItem.getName());
                }
            }
        });
        createWheelView2.setItems((List<?>) this.provider.linkageSecondData(this.selectedFirstIndex), this.selectedSecondIndex);
        createWheelView2.setOnItemSelectListener(new WheelView.OnItemSelectListener() { // from class: cn.qqtheme.framework.picker.LinkagePicker.2
            @Override // cn.qqtheme.framework.widget.WheelView.OnItemSelectListener
            public void onSelected(int i) {
                LinkagePicker linkagePicker = LinkagePicker.this;
                linkagePicker.selectedSecondItem = linkagePicker.provider.linkageSecondData(LinkagePicker.this.selectedFirstIndex).get(i);
                LinkagePicker linkagePicker2 = LinkagePicker.this;
                linkagePicker2.selectedSecondIndex = i;
                if (!linkagePicker2.provider.isOnlyTwo()) {
                    LogUtils.verbose(this, "change third data after second wheeled");
                    LinkagePicker linkagePicker3 = LinkagePicker.this;
                    linkagePicker3.selectedThirdIndex = 0;
                    List<?> linkageThirdData = linkagePicker3.provider.linkageThirdData(LinkagePicker.this.selectedFirstIndex, LinkagePicker.this.selectedSecondIndex);
                    LinkagePicker linkagePicker4 = LinkagePicker.this;
                    linkagePicker4.selectedThirdItem = linkageThirdData.get(linkagePicker4.selectedThirdIndex);
                    createWheelView3.setItems(linkageThirdData, LinkagePicker.this.selectedThirdIndex);
                }
                if (LinkagePicker.this.onWheelLinkageListener != null) {
                    LinkagePicker.this.onWheelLinkageListener.onLinkage(LinkagePicker.this.selectedFirstIndex, LinkagePicker.this.selectedSecondIndex, 0);
                }
                if (LinkagePicker.this.onWheelListener != null) {
                    LinkagePicker.this.onWheelListener.onSecondWheeled(LinkagePicker.this.selectedSecondIndex, LinkagePicker.this.selectedSecondItem.getName());
                }
            }
        });
        if (this.provider.isOnlyTwo()) {
            return linearLayout;
        }
        createWheelView3.setItems((List<?>) this.provider.linkageThirdData(this.selectedFirstIndex, this.selectedSecondIndex), this.selectedThirdIndex);
        createWheelView3.setOnItemSelectListener(new WheelView.OnItemSelectListener() { // from class: cn.qqtheme.framework.picker.LinkagePicker.3
            @Override // cn.qqtheme.framework.widget.WheelView.OnItemSelectListener
            public void onSelected(int i) {
                String obj;
                LinkagePicker linkagePicker = LinkagePicker.this;
                linkagePicker.selectedThirdItem = linkagePicker.provider.linkageThirdData(LinkagePicker.this.selectedFirstIndex, LinkagePicker.this.selectedSecondIndex).get(i);
                LinkagePicker linkagePicker2 = LinkagePicker.this;
                linkagePicker2.selectedThirdIndex = i;
                if (linkagePicker2.onWheelLinkageListener != null) {
                    LinkagePicker.this.onWheelLinkageListener.onLinkage(LinkagePicker.this.selectedFirstIndex, LinkagePicker.this.selectedSecondIndex, LinkagePicker.this.selectedThirdIndex);
                }
                if (LinkagePicker.this.onWheelListener != null) {
                    if (LinkagePicker.this.selectedThirdItem instanceof LinkageThird) {
                        obj = ((LinkageThird) LinkagePicker.this.selectedThirdItem).getName();
                    } else {
                        obj = LinkagePicker.this.selectedThirdItem.toString();
                    }
                    LinkagePicker.this.onWheelListener.onThirdWheeled(LinkagePicker.this.selectedThirdIndex, obj);
                }
            }
        });
        return linearLayout;
    }

    @Override // cn.qqtheme.framework.popup.ConfirmPopup
    public void onSubmit() {
        String obj;
        Fst selectedFirstItem = getSelectedFirstItem();
        Snd selectedSecondItem = getSelectedSecondItem();
        Trd selectedThirdItem = getSelectedThirdItem();
        if (this.provider.isOnlyTwo()) {
            OnPickListener onPickListener = this.onPickListener;
            if (onPickListener != null) {
                onPickListener.onPicked(selectedFirstItem, selectedSecondItem, null);
            }
            OnLinkageListener onLinkageListener = this.onLinkageListener;
            if (onLinkageListener != null) {
                onLinkageListener.onPicked(selectedFirstItem.getName(), selectedSecondItem.getName(), (String) null);
                return;
            }
            return;
        }
        OnPickListener onPickListener2 = this.onPickListener;
        if (onPickListener2 != null) {
            onPickListener2.onPicked(selectedFirstItem, selectedSecondItem, selectedThirdItem);
        }
        if (this.onLinkageListener != null) {
            if (selectedThirdItem instanceof LinkageThird) {
                obj = ((LinkageThird) selectedThirdItem).getName();
            } else {
                obj = selectedThirdItem.toString();
            }
            this.onLinkageListener.onPicked(selectedFirstItem.getName(), selectedSecondItem.getName(), obj);
        }
    }

    /* loaded from: classes.dex */
    public static abstract class OnStringPickListener implements OnPickListener<StringLinkageFirst, StringLinkageSecond, String> {
        public abstract void onPicked(String str, String str2, String str3);

        @Override // cn.qqtheme.framework.picker.LinkagePicker.OnPickListener
        public void onPicked(StringLinkageFirst stringLinkageFirst, StringLinkageSecond stringLinkageSecond, String str) {
            onPicked(stringLinkageFirst.getName(), stringLinkageSecond.getName(), str);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class StringLinkageFirst implements LinkageFirst<StringLinkageSecond> {
        private String name;
        private List<StringLinkageSecond> seconds;

        private StringLinkageFirst(String str, List<StringLinkageSecond> list) {
            this.seconds = new ArrayList();
            this.name = str;
            this.seconds = list;
        }

        @Override // cn.qqtheme.framework.entity.WheelItem
        public String getName() {
            return this.name;
        }

        @Override // cn.qqtheme.framework.entity.LinkageItem
        public Object getId() {
            return this.name;
        }

        @Override // cn.qqtheme.framework.entity.LinkageFirst
        public List<StringLinkageSecond> getSeconds() {
            return this.seconds;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class StringLinkageSecond implements LinkageSecond<String> {
        private String name;
        private List<String> thirds;

        private StringLinkageSecond(String str, List<String> list) {
            this.thirds = new ArrayList();
            this.name = str;
            this.thirds = list;
        }

        @Override // cn.qqtheme.framework.entity.WheelItem
        public String getName() {
            return this.name;
        }

        @Override // cn.qqtheme.framework.entity.LinkageItem
        public Object getId() {
            return this.name;
        }

        @Override // cn.qqtheme.framework.entity.LinkageSecond
        public List<String> getThirds() {
            return this.thirds;
        }
    }

    /* loaded from: classes.dex */
    public static abstract class DataProvider implements Provider<StringLinkageFirst, StringLinkageSecond, String> {
        public abstract List<String> provideFirstData();

        public abstract List<String> provideSecondData(int i);

        public abstract List<String> provideThirdData(int i, int i2);

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<StringLinkageFirst> initFirstData() {
            ArrayList arrayList = new ArrayList();
            int i = 0;
            for (String str : provideFirstData()) {
                arrayList.add(new StringLinkageFirst(str, linkageSecondData(i)));
                i++;
            }
            return arrayList;
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<StringLinkageSecond> linkageSecondData(int i) {
            ArrayList arrayList = new ArrayList();
            int i2 = 0;
            for (String str : provideSecondData(i)) {
                arrayList.add(new StringLinkageSecond(str, linkageThirdData(i, i2)));
                i2++;
            }
            return arrayList;
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<String> linkageThirdData(int i, int i2) {
            List<String> provideThirdData = provideThirdData(i, i2);
            return provideThirdData == null ? new ArrayList() : provideThirdData;
        }
    }

    /* loaded from: classes.dex */
    private static class DefaultDataProvider<Fst extends LinkageFirst<Snd>, Snd extends LinkageSecond<Trd>, Trd> implements Provider<Fst, Snd, Trd> {
        private List<Fst> firstList;
        private boolean onlyTwo;
        private List<List<Snd>> secondList;
        private List<List<List<Trd>>> thirdList;

        public DefaultDataProvider(List<Fst> list, List<List<Snd>> list2, List<List<List<Trd>>> list3) {
            this.firstList = new ArrayList();
            this.secondList = new ArrayList();
            this.thirdList = new ArrayList();
            this.onlyTwo = false;
            this.firstList = list;
            this.secondList = list2;
            if (list3 == null || list3.size() == 0) {
                this.onlyTwo = true;
            } else {
                this.thirdList = list3;
            }
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public boolean isOnlyTwo() {
            return this.onlyTwo;
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<Fst> initFirstData() {
            return this.firstList;
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<Snd> linkageSecondData(int i) {
            return this.secondList.get(i);
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<Trd> linkageThirdData(int i, int i2) {
            if (this.onlyTwo) {
                return new ArrayList();
            }
            return this.thirdList.get(i).get(i2);
        }
    }
}
